
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 01/22/2014 14:13:10
-- Generated from EDMX file: D:\Personal\Bogi\Borviz\Springwater\Springwater.Model\SWModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Springwater];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_BorvizFoldfelsziniHelyzet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FoldfelsziniHelyzet] DROP CONSTRAINT [FK_BorvizFoldfelsziniHelyzet];
GO
IF OBJECT_ID(N'[dbo].[FK_BorvizElnevezes]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Elnevezes] DROP CONSTRAINT [FK_BorvizElnevezes];
GO
IF OBJECT_ID(N'[dbo].[FK_VizgyujtoBorviz_Vizgyujto]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VizgyujtoBorviz] DROP CONSTRAINT [FK_VizgyujtoBorviz_Vizgyujto];
GO
IF OBJECT_ID(N'[dbo].[FK_VizgyujtoBorviz_Borviz]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VizgyujtoBorviz] DROP CONSTRAINT [FK_VizgyujtoBorviz_Borviz];
GO
IF OBJECT_ID(N'[dbo].[FK_MeresVizhozam]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Vizhozam] DROP CONSTRAINT [FK_MeresVizhozam];
GO
IF OBJECT_ID(N'[dbo].[FK_MeresMegfigyeles]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Megfigyeles] DROP CONSTRAINT [FK_MeresMegfigyeles];
GO
IF OBJECT_ID(N'[dbo].[FK_BorvizMeres]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Meres] DROP CONSTRAINT [FK_BorvizMeres];
GO
IF OBJECT_ID(N'[dbo].[FK_BorvizFenykep]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Fenykep] DROP CONSTRAINT [FK_BorvizFenykep];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Borviz]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Borviz];
GO
IF OBJECT_ID(N'[dbo].[FoldfelsziniHelyzet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FoldfelsziniHelyzet];
GO
IF OBJECT_ID(N'[dbo].[Meres]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Meres];
GO
IF OBJECT_ID(N'[dbo].[Elnevezes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Elnevezes];
GO
IF OBJECT_ID(N'[dbo].[Vizgyujto]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Vizgyujto];
GO
IF OBJECT_ID(N'[dbo].[Vizhozam]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Vizhozam];
GO
IF OBJECT_ID(N'[dbo].[Megfigyeles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Megfigyeles];
GO
IF OBJECT_ID(N'[dbo].[Fenykep]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Fenykep];
GO
IF OBJECT_ID(N'[dbo].[UserProfile]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserProfile];
GO
IF OBJECT_ID(N'[dbo].[VizgyujtoBorviz]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VizgyujtoBorviz];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Borviz'
CREATE TABLE [dbo].[Borviz] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Kod] nvarchar(20)  NOT NULL,
    [Tajegyseg] nvarchar(60)  NOT NULL,
    [Eredet] nvarchar(60)  NOT NULL,
    [Leiras] nvarchar(max)  NULL
);
GO

-- Creating table 'FoldfelsziniHelyzet'
CREATE TABLE [dbo].[FoldfelsziniHelyzet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Magassag] smallint  NOT NULL,
    [Latitude] decimal(18,14)  NULL,
    [Longitude] decimal(18,14)  NULL,
    [Borviz_Id] int  NOT NULL
);
GO

-- Creating table 'Meres'
CREATE TABLE [dbo].[Meres] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Datum] datetime  NOT NULL,
    [Gazfeltores] bit  NULL,
    [Homerseklet] float  NULL,
    [Kond] float  NULL,
    [TDS] int  NULL,
    [PH] float  NULL,
    [Sotartalom] float  NULL,
    [CO2] smallint  NULL,
    [HCO3] float  NULL,
    [Ca] smallint  NULL,
    [Mg] smallint  NULL,
    [NH4] float  NULL,
    [NO3] float  NULL,
    [Fe] float  NULL,
    [Cl] smallint  NULL,
    [PO4] smallint  NULL,
    [BorvizId] int  NOT NULL,
    [Szerzo] nvarchar(150)  NOT NULL
);
GO

-- Creating table 'Elnevezes'
CREATE TABLE [dbo].[Elnevezes] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nev] nvarchar(60)  NOT NULL,
    [Elsodleges] bit  NOT NULL,
    [BorvizId] int  NOT NULL
);
GO

-- Creating table 'Vizgyujto'
CREATE TABLE [dbo].[Vizgyujto] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nev] nvarchar(60)  NOT NULL,
    [Rang] smallint  NOT NULL
);
GO

-- Creating table 'Vizhozam'
CREATE TABLE [dbo].[Vizhozam] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Hozam] float  NULL,
    [NemMerheto] bit  NULL,
    [Elhanyagolhato] bit  NULL,
    [NemMerhetoNagyHozam] bit  NULL,
    [Meres_Id] int  NOT NULL
);
GO

-- Creating table 'Megfigyeles'
CREATE TABLE [dbo].[Megfigyeles] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Allapot] nvarchar(50)  NOT NULL,
    [Forma] nvarchar(150)  NOT NULL,
    [Kiepitettseg] nvarchar(150)  NOT NULL,
    [KornyezetiVeszely] nvarchar(150)  NOT NULL,
    [Meres_Id] int  NOT NULL
);
GO

-- Creating table 'Fenykep'
CREATE TABLE [dbo].[Fenykep] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Datum] datetime  NOT NULL,
    [File] nvarchar(max)  NOT NULL,
    [BorvizId] int  NOT NULL,
    [Szerzo] nvarchar(150)  NOT NULL,
    [Elsodleges] bit  NOT NULL
);
GO

-- Creating table 'UserProfile'
CREATE TABLE [dbo].[UserProfile] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(56)  NOT NULL,
    [Email] varchar(100)  NULL,
    [FirstName] nvarchar(100)  NULL,
    [LastName] nvarchar(100)  NULL,
    [PhoneNumber] varchar(50)  NULL
);
GO

-- Creating table 'VizgyujtoBorviz'
CREATE TABLE [dbo].[VizgyujtoBorviz] (
    [Vizgyujtok_Id] int  NOT NULL,
    [Borvizek_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Borviz'
ALTER TABLE [dbo].[Borviz]
ADD CONSTRAINT [PK_Borviz]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FoldfelsziniHelyzet'
ALTER TABLE [dbo].[FoldfelsziniHelyzet]
ADD CONSTRAINT [PK_FoldfelsziniHelyzet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Meres'
ALTER TABLE [dbo].[Meres]
ADD CONSTRAINT [PK_Meres]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Elnevezes'
ALTER TABLE [dbo].[Elnevezes]
ADD CONSTRAINT [PK_Elnevezes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Vizgyujto'
ALTER TABLE [dbo].[Vizgyujto]
ADD CONSTRAINT [PK_Vizgyujto]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Vizhozam'
ALTER TABLE [dbo].[Vizhozam]
ADD CONSTRAINT [PK_Vizhozam]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Megfigyeles'
ALTER TABLE [dbo].[Megfigyeles]
ADD CONSTRAINT [PK_Megfigyeles]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Fenykep'
ALTER TABLE [dbo].[Fenykep]
ADD CONSTRAINT [PK_Fenykep]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserProfile'
ALTER TABLE [dbo].[UserProfile]
ADD CONSTRAINT [PK_UserProfile]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Vizgyujtok_Id], [Borvizek_Id] in table 'VizgyujtoBorviz'
ALTER TABLE [dbo].[VizgyujtoBorviz]
ADD CONSTRAINT [PK_VizgyujtoBorviz]
    PRIMARY KEY NONCLUSTERED ([Vizgyujtok_Id], [Borvizek_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Borviz_Id] in table 'FoldfelsziniHelyzet'
ALTER TABLE [dbo].[FoldfelsziniHelyzet]
ADD CONSTRAINT [FK_BorvizFoldfelsziniHelyzet]
    FOREIGN KEY ([Borviz_Id])
    REFERENCES [dbo].[Borviz]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BorvizFoldfelsziniHelyzet'
CREATE INDEX [IX_FK_BorvizFoldfelsziniHelyzet]
ON [dbo].[FoldfelsziniHelyzet]
    ([Borviz_Id]);
GO

-- Creating foreign key on [BorvizId] in table 'Elnevezes'
ALTER TABLE [dbo].[Elnevezes]
ADD CONSTRAINT [FK_BorvizElnevezes]
    FOREIGN KEY ([BorvizId])
    REFERENCES [dbo].[Borviz]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BorvizElnevezes'
CREATE INDEX [IX_FK_BorvizElnevezes]
ON [dbo].[Elnevezes]
    ([BorvizId]);
GO

-- Creating foreign key on [Vizgyujtok_Id] in table 'VizgyujtoBorviz'
ALTER TABLE [dbo].[VizgyujtoBorviz]
ADD CONSTRAINT [FK_VizgyujtoBorviz_Vizgyujto]
    FOREIGN KEY ([Vizgyujtok_Id])
    REFERENCES [dbo].[Vizgyujto]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Borvizek_Id] in table 'VizgyujtoBorviz'
ALTER TABLE [dbo].[VizgyujtoBorviz]
ADD CONSTRAINT [FK_VizgyujtoBorviz_Borviz]
    FOREIGN KEY ([Borvizek_Id])
    REFERENCES [dbo].[Borviz]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VizgyujtoBorviz_Borviz'
CREATE INDEX [IX_FK_VizgyujtoBorviz_Borviz]
ON [dbo].[VizgyujtoBorviz]
    ([Borvizek_Id]);
GO

-- Creating foreign key on [Meres_Id] in table 'Vizhozam'
ALTER TABLE [dbo].[Vizhozam]
ADD CONSTRAINT [FK_MeresVizhozam]
    FOREIGN KEY ([Meres_Id])
    REFERENCES [dbo].[Meres]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MeresVizhozam'
CREATE INDEX [IX_FK_MeresVizhozam]
ON [dbo].[Vizhozam]
    ([Meres_Id]);
GO

-- Creating foreign key on [Meres_Id] in table 'Megfigyeles'
ALTER TABLE [dbo].[Megfigyeles]
ADD CONSTRAINT [FK_MeresMegfigyeles]
    FOREIGN KEY ([Meres_Id])
    REFERENCES [dbo].[Meres]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MeresMegfigyeles'
CREATE INDEX [IX_FK_MeresMegfigyeles]
ON [dbo].[Megfigyeles]
    ([Meres_Id]);
GO

-- Creating foreign key on [BorvizId] in table 'Meres'
ALTER TABLE [dbo].[Meres]
ADD CONSTRAINT [FK_BorvizMeres]
    FOREIGN KEY ([BorvizId])
    REFERENCES [dbo].[Borviz]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BorvizMeres'
CREATE INDEX [IX_FK_BorvizMeres]
ON [dbo].[Meres]
    ([BorvizId]);
GO

-- Creating foreign key on [BorvizId] in table 'Fenykep'
ALTER TABLE [dbo].[Fenykep]
ADD CONSTRAINT [FK_BorvizFenykep]
    FOREIGN KEY ([BorvizId])
    REFERENCES [dbo].[Borviz]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BorvizFenykep'
CREATE INDEX [IX_FK_BorvizFenykep]
ON [dbo].[Fenykep]
    ([BorvizId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------